<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>新建审批</el-breadcrumb-item>
      <el-breadcrumb-item>新建审批</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="always">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="审批名称" prop="name">
          <el-input
            v-model="ruleForm.name"
            placeholder="请输入文件名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="文件类型" prop="region">
          <el-select v-model="ruleForm.region" placeholder="请选择文件类型">
            <el-option label="合同" value="shanghai"></el-option>
          </el-select>
        </el-form-item>

        <div class="time">
          <el-form-item label="发起时间" required>
            <el-col :span="22">
              <el-form-item prop="date1">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="ruleForm.date1"
                  style="width: 100%"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>

          <el-form-item label="截止日期" required>
            <el-col :span="22">
              <el-form-item prop="date1">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="ruleForm.date1"
                  style="width: 100%"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>
        </div>

        <el-form-item label="签署顺序" prop="resource">
          <el-radio-group v-model="ruleForm.resource">
            <el-radio label="有序签署"></el-radio>
            <el-radio label="无序签署"></el-radio>
          </el-radio-group>
        </el-form-item>

        <div class="time">
          <el-form-item label="归属项目" prop="region">
            <el-select v-model="ruleForm.region" placeholder="请选择归属项目">
              <el-option label="合同" value="shanghai"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="归属部门" prop="region">
            <el-select
              v-model="ruleForm.region"
              placeholder="请选择归属部门"
              :span="25"
            >
              <el-option label="合同" value="shanghai"></el-option>
            </el-select>
          </el-form-item>
        </div>

        <el-form-item label="审批文件" prop="region">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-change="handleChange"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="tip">
              文件类型仅限 pdf/png/jpg
            </div>
          </el-upload>
        </el-form-item>

        <el-form-item label="添加附件">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-change="handleChange"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="tip">
              附件类型不限
            </div>
          </el-upload>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
    fileList:[],
      ruleForm: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change",
          },
        ],
        resource: [
          { required: true, message: "请选择活动资源", trigger: "change" },
        ],
        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleChange(file, fileList) {
        this.fileList = fileList.slice(-3);
      }
  },
};
</script>

<style lang="less" scoped>
.time {
  display: flex;
}
.tip{
    font-size: 5px;
    color: #ccc;
}
</style>